﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GomeeSoft.src.classes;
using GomeeSoft.src.form.DiaryPages;

namespace GomeeSoft.src.form
{
    public partial class FormMain : Form
    {
        // [Region] Variable ===========================================================
        #region Variable
        private int borderSize = 13;
        private PagesInDiary selectedPage = PagesInDiary.Login;
        public PagesInDiary SelectedPage
        {
            get { return selectedPage; }
            set { selectedPage = value; FormMain_OnPageSelected(); }
        }
        private Rectangle logoRange;
        private Rectangle pageLeftRange;
        private Rectangle pageRightRange;
        private Rectangle sideMenuRange;
        private Rectangle[] sideMenusRange = new Rectangle[8];
        private Rectangle borderTopLeft;
        private Rectangle borderTopRight;
        private Rectangle borderTop;
        private Rectangle borderLeft;
        private Rectangle borderRight;
        private Rectangle borderBottomLeft;
        private Rectangle borderBottomRight;
        private Rectangle borderBottom;
        #endregion

        // [Region] Initialize =========================================================
        #region Initialize
        public FormMain()
        {
            InitializeComponent();
            InitializeForm();
            InitializeLogo();
            ucLoginR.Focus();
        }
        private void InitializeForm()
        {
            BackColor = Global.GetColor(Global.FromBackColor);
            FormBorderStyle = FormBorderStyle.None;
            FormMain_OnPageSelected();
        }
        private void InitializeLogo()
        {
            Font f = new Font(lb_company.Font.SystemFontName, 11F, FontStyle.Bold, GraphicsUnit.Pixel);
            Color c = Global.GetColor(Global.LogoTextColor);
            lb_company.Font = f;
            lb_company.ForeColor = c;
            lb_url.ForeColor = c;
            lb_urllink.ActiveLinkColor = c;
            lb_urllink.LinkColor = c;
            lb_urllink.VisitedLinkColor = c;
            lb_email.ForeColor = c;
            lb_emaillink.ActiveLinkColor = c;
            lb_emaillink.LinkColor = c;
            lb_emaillink.VisitedLinkColor = c;
        }
        private void InitializeRing()
        {
            pb_ring1.BringToFront();
            pb_ring2.BringToFront();
            pb_ring3.BringToFront();
            pb_ring4.BringToFront();
            pb_ring5.BringToFront();
            pb_ring6.BringToFront();
        }
        #endregion

        // [Region] Resize =============================================================
        #region Resize
        private void FormMain_Resize(object sender, EventArgs e)
        {
            ResizeForm(sender, e);
            ResizeLogo(sender, e);
            ResizePageBorder(sender, e);
            ResizeSideMenu(sender, e);
            ResizeRing(sender, e);
            ResizePageContent(sender, e);
            ResizeMinMaxButton(sender, e);
            Invalidate();
        }
        private void ResizeForm(object sender, EventArgs e)
        {
            borderTopLeft = new Rectangle(0, 0, borderSize, borderSize);
            borderTopRight = new Rectangle(Width - borderSize, 0, borderSize, borderSize);
            borderTop = new Rectangle(borderSize, 0, Width - 2 * borderSize, borderSize);
            borderLeft = new Rectangle(0, borderSize, borderSize, Height - 2 * borderSize);
            borderRight = new Rectangle(Width - borderSize, borderSize, borderSize, Height - 2 * borderSize);
            borderBottomLeft = new Rectangle(0, Height - borderSize, borderSize, borderSize);
            borderBottomRight = new Rectangle(Width - borderSize, Height - borderSize, borderSize, borderSize);
            borderBottom = new Rectangle(borderSize, Height - borderSize, Width - 2 * borderSize, borderSize);
        }
        private void ResizeLogo(object sender, EventArgs e)
        {
            Size s = new Size(215,92);
            Point p = new Point(((Width - 49) / 2 - 17 - s.Width) / 2, Height - 145);
            logoRange = new Rectangle(p, s);
            p.Offset(14, 14);
            lb_company.Location = p;
            p.Offset(0, 31);
            lb_url.Location = p;
            p.Offset(29, 0);
            lb_urllink.Location = p;
            p.Offset(-29, 18);
            lb_email.Location = p;
            p.Offset(34, 0);
            lb_emaillink.Location = p;
        }
        private void ResizePageBorder(object sender, EventArgs e)
        {
            Point p = new Point(35, 15);
            Size s = new Size((Width - 105) / 2, Height - 30);
            pageLeftRange = new Rectangle(p, s);
            p = new Point((Width + 35) / 2, 15);
            pageRightRange = new Rectangle(p, s);
        }
        private void ResizeSideMenu(object sender, EventArgs e)
        {
            Point p = new Point(pageRightRange.Left + pageRightRange.Width - 3, 21);
            Size s = new Size(27, (Height -41) / 8 + 1);
            sideMenuRange = new Rectangle(p, s);
        }
        private void ResizeRing(object sender, EventArgs e)
        {
            Point p = new Point((Width - pb_ring1.Width) / 2, 2 * Height / 12 - 3);
            pb_ring1.Location = p;
            p.Offset(0, Height / 12);
            pb_ring2.Location = p;
            p.Offset(0, Height / 12);
            pb_ring3.Location = p;
            p.Offset(0, 4 * Height / 12);
            pb_ring4.Location = p;
            p.Offset(0, Height / 12);
            pb_ring5.Location = p;
            p.Offset(0, Height / 12);
            pb_ring6.Location = p;
        }
        private void ResizePageContent(object sender, EventArgs e)
        {
            Point p = pageLeftRange.Location;
            Size s = pageLeftRange.Size;
            p.Offset(7, 7);
            s.Width = s.Width - 28;
            s.Height = s.Height - 16;
            Rectangle pageContentLeftRange = new Rectangle(p, s);
            p = pageRightRange.Location;
            p.Offset(21, 7);
            Rectangle pageContentRightRange = new Rectangle(p, s);

            // Left Page
            ucMonthL.Location = pageContentLeftRange.Location;
            ucMonthL.Size = pageContentLeftRange.Size;
            ucScheduleL.Location = pageContentLeftRange.Location;
            ucScheduleL.Size = pageContentLeftRange.Size;
            ucDiaryL.Location = pageContentLeftRange.Location;
            ucDiaryL.Size = pageContentLeftRange.Size;
            ucContactL.Location = pageContentLeftRange.Location;
            ucContactL.Size = pageContentLeftRange.Size;
            ucMoneyL.Location = pageContentLeftRange.Location;
            ucMoneyL.Size = pageContentLeftRange.Size;
            ucCarL.Location = pageContentLeftRange.Location;
            ucCarL.Size = pageContentLeftRange.Size;
            ucProjectL.Location = pageContentLeftRange.Location;
            ucProjectL.Size = pageContentLeftRange.Size;
            ucDataL.Location = pageContentLeftRange.Location;
            ucDataL.Size = pageContentLeftRange.Size;

            // Right Page
            ucLoginR.Location = pageContentRightRange.Location;
            ucLoginR.Size = pageContentRightRange.Size;
            ucMonthR.Location = pageContentRightRange.Location;
            ucMonthR.Size = pageContentRightRange.Size;
            ucScheduleR.Location = pageContentRightRange.Location;
            ucScheduleR.Size = pageContentRightRange.Size;
            ucDiaryR.Location = pageContentRightRange.Location;
            ucDiaryR.Size = pageContentRightRange.Size;
            ucContactR.Location = pageContentRightRange.Location;
            ucContactR.Size = pageContentRightRange.Size;
            ucMoneyR.Location = pageContentRightRange.Location;
            ucMoneyR.Size = pageContentRightRange.Size;
            ucCarR.Location = pageContentRightRange.Location;
            ucCarR.Size = pageContentRightRange.Size;
            ucProjectR.Location = pageContentRightRange.Location;
            ucProjectR.Size = pageContentRightRange.Size;
            ucDataR.Location = pageContentRightRange.Location;
            ucDataR.Size = pageContentRightRange.Size;
        }
        private void ResizeMinMaxButton(object sender, EventArgs e)
        {
            Point p = new Point(Width - 130, 42);
            pb_min.Location = p;
            p.Offset(30, 0);
            pb_max.Location = p;
            p.Offset(30, 0);
            pb_close.Location = p;
        }
        #endregion

        // [Region] Paint ==============================================================
        #region Paint
        private void FormMain_Paint(object sender, PaintEventArgs e)
        {
            SuspendLayout();
            PaintFrame(sender, e);
            PaintBinder(sender, e);
            switch (SelectedPage)
            {
                case PagesInDiary.Login:
                    PaintLogo(sender, e);
                    PaintRightPage(sender, e);
                    break;
                default:
                    PaintLeftPage(sender, e);
                    PaintRightPage(sender, e);
                    break;
            }
            PaintSideMenu(sender, e);
            ResumeLayout();
        }
        private void PaintFrame(object sender, PaintEventArgs e)
        {
            Point p = new Point(0, 0);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_lt1, p);
            p.Offset(GomeeSoft.Properties.Resources.frame_lt1.Width, 0);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_lt2, p);
            p.Offset(-GomeeSoft.Properties.Resources.frame_lt1.Width, GomeeSoft.Properties.Resources.frame_lt1.Height);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_lt3, p);
            p = new Point(Width - GomeeSoft.Properties.Resources.frame_rt1.Width, 0);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_rt1, p);
            p.Offset(0, GomeeSoft.Properties.Resources.frame_rt1.Height);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_rt2, p);
            p.Offset(-GomeeSoft.Properties.Resources.frame_rt3.Width, -GomeeSoft.Properties.Resources.frame_rt1.Height);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_rt3, p);
            p = new Point(0, Height - GomeeSoft.Properties.Resources.frame_lb1.Height);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_lb1, p);
            p.Offset(0, -GomeeSoft.Properties.Resources.frame_lb2.Height);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_lb2, p);
            p.Offset(GomeeSoft.Properties.Resources.frame_lb1.Width, GomeeSoft.Properties.Resources.frame_lb2.Height);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_lb3, p);
            p = new Point(Width - GomeeSoft.Properties.Resources.frame_rb1.Width, Height - GomeeSoft.Properties.Resources.frame_rb1.Height);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_rb1, p);
            p.Offset(-GomeeSoft.Properties.Resources.frame_rb2.Width, 0);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_rb2, p);
            p.Offset(GomeeSoft.Properties.Resources.frame_rb2.Width, -GomeeSoft.Properties.Resources.frame_rb3.Height);
            e.Graphics.DrawImage(GomeeSoft.Properties.Resources.frame_rb3, p);
        }
        private void PaintBinder(object sender, PaintEventArgs e)
        {
            Point p = new Point((Width - GomeeSoft.Properties.Resources.binder.Width) / 2, 8);
            Size s = new Size(49, Height - 38);
            Rectangle r = new Rectangle(0, 0, 49, 11);
            Image i = BitmapEdit.CropBitmap(GomeeSoft.Properties.Resources.binder, r);
            e.Graphics.DrawImage(i, p);
            p.Offset(0, i.Height);
            r = new Rectangle(0, 10, 49, 1);
            i = BitmapEdit.CropBitmap(GomeeSoft.Properties.Resources.binder, r);
            TextureBrush b = new TextureBrush(i);
            b.TranslateTransform(p.X, p.Y);
            e.Graphics.FillRectangle(b, new Rectangle(p, s));
            p.Offset(0, s.Height);
            r = new Rectangle(0, 10, 49, 11);
            i = BitmapEdit.CropBitmap(GomeeSoft.Properties.Resources.binder, r);
            e.Graphics.DrawImage(i, p);

            p = new Point((Width - GomeeSoft.Properties.Resources.binder.Width) / 2 - 17, 0);
            s = new Size(4, Height);
            i = GomeeSoft.Properties.Resources.folding;
            b = new TextureBrush(i);
            b.TranslateTransform(p.X, p.Y);
            e.Graphics.FillRectangle(b, new Rectangle(p, s));
            p = new Point((Width + GomeeSoft.Properties.Resources.binder.Width) / 2 + 13, 0);
            e.Graphics.FillRectangle(b, new Rectangle(p, s));
        }
        private void PaintLogo(object sender, PaintEventArgs e)
        {
            Pen p = new Pen(Global.GetColor(Global.LogoBorderColor1));
            Point l = logoRange.Location;
            Size s = new Size(logoRange.Width - 1, logoRange.Height - 1);
            e.Graphics.DrawRectangle(p, new Rectangle(l, s));
            s = new Size(logoRange.Width - 2, logoRange.Height - 2);
            e.Graphics.DrawRectangle(p, new Rectangle(l, s));
            l.Offset(1, 1);
            p = new Pen(Global.GetColor(Global.LogoBorderColor2));
            e.Graphics.DrawRectangle(p, new Rectangle(l, s));
        }
        private void PaintLeftPage(object sender, PaintEventArgs e)
        {
            PaintPage(e.Graphics, pageLeftRange);
        }
        private void PaintRightPage(object sender, PaintEventArgs e)
        {
            PaintPage(e.Graphics, pageRightRange);
        }
        private void PaintPage(Graphics g, Rectangle r)
        {
            Pen c;
            Point[] p = new Point[3];
            p[0] = new Point(r.X, r.Y + r.Height - 1);
            p[1] = new Point(r.X, r.Y);
            p[2] = new Point(r.X + r.Width - 1, r.Y);
            
            for (int i = 0; i < 4; i++)
            {
                c = new Pen(Global.GetColor(Global.PageBorderLightColor[i]));
                g.DrawLines(c, p);
                p[0].Offset(1, -1);
                p[1].Offset(1, 1);
                p[2].Offset(-1, 1);
            }

            p[0] = new Point(r.X + 1, r.Y + r.Height - 1);
            p[1] = new Point(r.X + r.Width - 1, r.Y + r.Height - 1);
            p[2] = new Point(r.X + r.Width - 1, r.Y + 1); 

            for (int i = 0; i < 4; i++)
            {
                c = new Pen(Global.GetColor(Global.PageBorderDarkColor[i]));
                g.DrawLines(c, p);
                p[0].Offset(1, -1);
                p[1].Offset(- 1, - 1);
                p[2].Offset(-1, 1);
            }

            p[0] = r.Location;
            Size s = r.Size;
            p[0].Offset(4, 4);
            s.Width = s.Width - 8;
            s.Height = s.Height - 8;
            g.FillRectangle(new SolidBrush(Color.White), new Rectangle(p[0], s));
        }
        private void PaintSideMenu(object sender, PaintEventArgs e)
        {
            Point p = sideMenuRange.Location;
            Size s = sideMenuRange.Size;
            Font f = new Font(Font.FontFamily, 10);
            SolidBrush b = new SolidBrush(Color.Gray);

            for (int i = 0; i < 8; i++)
            {
                s.Height = GetSideMenuHeightSize(i);
                if (SelectedPage == Global.GetPagesInDiaryByIndex(i))
                {
                    s.Width = 28;
                    sideMenusRange[i] = new Rectangle(p, s);
                    e.Graphics.FillRectangle(new SolidBrush(Global.GetColor(Global.SideMenuBorderColor[0])), new Rectangle(p, s));
                    p.Offset(0, 1);
                    s.Width = s.Width - 1;
                    s.Height = s.Height - 2;
                    e.Graphics.FillRectangle(new SolidBrush(Global.GetColor(Global.SideMenuBorderColor[1])), new Rectangle(p, s));
                    p.Offset(0, 1);
                    s.Width = s.Width - 1;
                    s.Height = s.Height - 2;
                    e.Graphics.FillRectangle(new SolidBrush(Global.GetColor(Global.SideMenuBorderColor[2])), new Rectangle(p, s));
                    p.Offset(0, 2);
                    s.Width = s.Width - 2;
                    s.Height = s.Height - 4;
                    e.Graphics.FillRectangle(new SolidBrush(Global.GetColor(Global.SideMenuBackColor[i])), new Rectangle(p, s));
                    e.Graphics.RotateTransform(90);
                    e.Graphics.DrawString(Global.StringMenu[i], f, b, p.Y, -p.X - s.Width);
                    e.Graphics.RotateTransform(-90);
                    p.Offset(0, s.Height + 3);
                    s.Width = s.Width + 4;
                    s.Height = s.Height + 8;
                }
                else
                {
                    p.Offset(3, 0);
                    s.Width = 21;
                    sideMenusRange[i] = new Rectangle(p, s);
                    e.Graphics.FillRectangle(new SolidBrush(Global.GetColor(Global.SideMenuBorderColor[0])), new Rectangle(p, s));
                    p.Offset(0, 1);
                    s.Width = s.Width - 1;
                    s.Height = s.Height - 2;
                    e.Graphics.FillRectangle(new SolidBrush(Global.GetColor(Global.SideMenuBorderColor[1])), new Rectangle(p, s));
                    p.Offset(0, 1);
                    s.Width = s.Width - 1;
                    s.Height = s.Height - 2;
                    e.Graphics.FillRectangle(new SolidBrush(Global.GetColor(Global.SideMenuBorderColor[2])), new Rectangle(p, s));
                    p.Offset(0, 1);
                    s.Width = s.Width - 1;
                    s.Height = s.Height - 2;
                    e.Graphics.FillRectangle(new SolidBrush(Global.GetColor(Global.SideMenuBackColor[i])), new Rectangle(p, s));
                    e.Graphics.RotateTransform(90);
                    e.Graphics.DrawString(Global.StringMenu[i], f, b, p.Y, -p.X - s.Width);
                    e.Graphics.RotateTransform(-90);
                    p.Offset(-3, s.Height + 2);
                    s.Width = s.Width + 3;
                    s.Height = s.Height + 6;
                }
            }
        }
        private int GetSideMenuHeightSize(int i)
        {
            int menuHeight = (Height - 41) / 8 + 1;
            switch (Height - 41 - (menuHeight - 1) * 8)
            {
                case 1:
                    if (i == 0)
                        return menuHeight + 1;
                    else
                        return menuHeight;
                case 2:
                    if (i == 0 || i == 4)
                        return menuHeight + 1;
                    else
                        return menuHeight;
                case 3:
                    if (i == 0 || i == 3 || i == 6)
                        return menuHeight + 1;
                    else
                        return menuHeight;
                case 4:
                    if (i == 0 || i == 2 || i == 4 || i == 6)
                        return menuHeight + 1;
                    else
                        return menuHeight;
                case 5:
                    if (i == 1 || i == 4 || i == 7)
                        return menuHeight;
                    else
                        return menuHeight + 1;
                case 6:
                    if (i == 3 || i == 7)
                        return menuHeight;
                    else
                        return menuHeight + 1;
                case 7:
                    if (i == 7)
                        return menuHeight;
                    else
                        return menuHeight + 1;
                default:
                    return menuHeight;
            }
        }
        #endregion

        // [Region] OnPageSelect =======================================================
        #region OnPageSelect
        private void FormMain_OnPageSelected()
        {
            VisibleLoginPage(false);
            VisibleMonthPage(false);
            VisibleSchedulePage(false);
            VisibleDiaryPage(false);
            VisibleContactPage(false);
            VisibleMoneyPage(false);
            VisibleCarPage(false);
            VisibleProjectPage(false);
            VisibleDataPage(false);

            switch (SelectedPage)
            {
                case PagesInDiary.Login:
                    VisibleLoginPage(true);
                    break;
                case PagesInDiary.Month:
                    VisibleMonthPage(true);
                    break;
                case PagesInDiary.Schedule:
                    VisibleSchedulePage(true);
                    break;
                case PagesInDiary.Diary:
                    VisibleDiaryPage(true);
                    break;
                case PagesInDiary.Contact:
                    VisibleContactPage(true);
                    break;
                case PagesInDiary.Money:
                    VisibleMoneyPage(true);
                    break;
                case PagesInDiary.Car:
                    VisibleCarPage(true);
                    break;
                case PagesInDiary.Project:
                    VisibleProjectPage(true);
                    break;
                case PagesInDiary.Data:
                    VisibleDataPage(true);
                    break;
            }
            Invalidate();
        }
        private void VisibleLoginPage(bool visible)
        {
            lb_company.Visible = visible;
            lb_url.Visible = visible;
            lb_urllink.Visible = visible;
            lb_email.Visible = visible;
            lb_emaillink.Visible = visible;
            ucLoginR.Visible = visible;
        }
        private void VisibleMonthPage(bool visible)
        {
            ucMonthL.Visible = visible;
            ucMonthR.Visible = visible;
        }
        private void VisibleSchedulePage(bool visible)
        {
            ucScheduleL.Visible = visible;
            ucScheduleR.Visible = visible;
        }
        private void VisibleDiaryPage(bool visible)
        {
            ucDiaryL.Visible = visible;
            ucDiaryR.Visible = visible;
        }
        private void VisibleContactPage(bool visible)
        {
            ucContactL.Visible = visible;
            ucContactR.Visible = visible;
        }
        private void VisibleMoneyPage(bool visible)
        {
            ucMoneyL.Visible = visible;
            ucMoneyR.Visible = visible;
        }
        private void VisibleCarPage(bool visible)
        {
            ucCarL.Visible = visible;
            ucCarR.Visible = visible;
        }
        private void VisibleProjectPage(bool visible)
        {
            ucProjectL.Visible = visible;
            ucProjectR.Visible = visible;
        }
        private void VisibleDataPage(bool visible)
        {
            ucDataL.Visible = visible;
            ucDataR.Visible = visible;
        }
        #endregion

        // [Region] Override Logic =====================================================
        #region OVerride Logic
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            switch(m.Msg)
            {
                case Global.WM_NCHITTEST:
                    Point mouseCursor = PointToClient(Cursor.Position);

                    if (borderTopLeft.Contains(mouseCursor))
                        m.Result = (IntPtr)Global.HTTOPLEFT;
                    else if (borderTopRight.Contains(mouseCursor))
                        m.Result = (IntPtr)Global.HTTOPRIGHT;
                    else if (borderBottomLeft.Contains(mouseCursor))
                        m.Result = (IntPtr)Global.HTBOTTOMLEFT;
                    else if (borderBottomRight.Contains(mouseCursor))
                        m.Result = (IntPtr)Global.HTBOTTOMRIGHT;
                    else if (borderTop.Contains(mouseCursor))
                        m.Result = (IntPtr)Global.HTTOP;
                    else if (borderBottom.Contains(mouseCursor))
                        m.Result = (IntPtr)Global.HTBOTTOM;
                    else if (borderLeft.Contains(mouseCursor))
                        m.Result = (IntPtr)Global.HTLEFT;
                    else if (borderRight.Contains(mouseCursor))
                        m.Result = (IntPtr)Global.HTRIGHT;
                    else if (!sideMenusRange[0].Contains(mouseCursor) &&
                             !sideMenusRange[1].Contains(mouseCursor) &&
                             !sideMenusRange[2].Contains(mouseCursor) &&
                             !sideMenusRange[3].Contains(mouseCursor) &&
                             !sideMenusRange[4].Contains(mouseCursor) &&
                             !sideMenusRange[5].Contains(mouseCursor) &&
                             !sideMenusRange[6].Contains(mouseCursor) &&
                             !sideMenusRange[7].Contains(mouseCursor))
                        m.Result = (IntPtr)Global.HTCAPTION;
                    break;
                case Global.WM_SYSCOMMAND:
                    switch (m.WParam.ToInt32() & 0xfff0)
                    {
                        case Global.SC_MAXIMIZE:
                            pb_max.Image = GomeeSoft.Properties.Resources.buttonreturn;
                            break;
                        case Global.SC_MINIMIZE:
                            break;
                        case Global.SC_RESTORE:
                            pb_max.Image = GomeeSoft.Properties.Resources.buttonmax;
                            break;
                    }
                    Invalidate();
                    break;
            }
        }
        
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }
        #endregion

        // [Region] Business Logic =====================================================
        #region Business Logic
        private void lb_urllink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(lb_urllink.Text);
        }
        private void lb_emaillink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("mailto:" + lb_emaillink.Text);
        }
        private void pb_close_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void pb_max_Click(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Maximized)
            {
                WindowState = FormWindowState.Normal;
                pb_max.Image = GomeeSoft.Properties.Resources.buttonmax;
            }
            else
            {
                Screen screen = Screen.FromRectangle(new Rectangle(Left, Top, Width, Height));
                pb_max.Image = GomeeSoft.Properties.Resources.buttonreturn;
                this.MaximumSize = screen.WorkingArea.Size;
                WindowState = FormWindowState.Maximized;
            }
            Invalidate();
        }
        private void pb_min_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }
        private void FormMain_Click(object sender, EventArgs e)
        {
            Point p = PointToClient(Cursor.Position);

            if (SelectedPage == PagesInDiary.Login)
                MessageBox.Show("Please login to use diary pages.");
            else if (sideMenusRange[0].Contains(p))
                SelectedPage = PagesInDiary.Month;
            else if (sideMenusRange[1].Contains(p))
                SelectedPage = PagesInDiary.Schedule;
            else if (sideMenusRange[2].Contains(p))
                SelectedPage = PagesInDiary.Diary;
            else if (sideMenusRange[3].Contains(p))
                SelectedPage = PagesInDiary.Contact;
            else if (sideMenusRange[4].Contains(p))
                SelectedPage = PagesInDiary.Money;
            else if (sideMenusRange[5].Contains(p))
                SelectedPage = PagesInDiary.Car;
            else if (sideMenusRange[6].Contains(p))
                SelectedPage = PagesInDiary.Project;
            else if (sideMenusRange[7].Contains(p))
                SelectedPage = PagesInDiary.Data;
        }
        #endregion

        // [Region] Event Logic ========================================================
        #region Event Logic
        private void ucLoginR_LoggedIn(object sender, EventArgs e)
        {
            SelectedPage = PagesInDiary.Month;
        }
        private void ucMonthL_OnMonthChange(object sender, EventArgs e, int year, int month)
        {
            ucMonthR.Year = year;
            ucMonthR.Month = month;
        }
        #endregion
    }
}
